package org.compiere.model;

import java.sql.ResultSet;
import java.util.Properties;

import org.compiere.apps.IProcessParameter;
import org.compiere.apps.ProcessCtl;
import org.compiere.apps.ProcessParameterPanel;
import org.compiere.process.ProcessInfo;
import org.compiere.util.ASyncProcess;
import org.compiere.util.DB;

public class Mcmsproposal extends X_cms_proposal implements  ASyncProcess {

	/**
	 * 
	 */
	private static final long serialVersionUID = -2034238679614099307L;

	public Mcmsproposal(Properties ctx) {
		super(ctx);
	}
	
	public Mcmsproposal(Properties ctx, int cms_proposal_ID, String trxName)
	{
		super(ctx, cms_proposal_ID, trxName);
	}
	
	public Mcmsproposal(Properties ctx, ResultSet rs, String trxName)
	{
		super(ctx, rs, trxName);
	}
	
	/**************************************************************************
	 * 	After Save
	 *	@param newRecord new
	 *	@param success success
	 *	@return success
	 */
	protected boolean afterSave (boolean newRecord, boolean success)
	{
		if(this.isApproved())
			return true;
		
		int ad_process_id = getProcess();
		ProcessInfo pi = new ProcessInfo("Inform header", ad_process_id, this.get_Table_ID(), this.get_ID());
		pi.setAD_Client_ID(this.getAD_Client_ID());
		pi.setAD_User_ID(this.getAD_User_ID());
		
		ProcessParameterPanel pu = new ProcessParameterPanel(0, pi);
		ProcessCtl.process(this, 0, (IProcessParameter) pu, pi, null);
		//ProcessCtl.pr
		
		return success;
	}	//	afterSave

	private int getProcess()
	{
		String sql = "SELECT AD_Process_ID FROM AD_Process WHERE LOWER(Name) LIKE '%cms_informheader%'";
		
		int ad_process_id = DB.getSQLValue(get_TrxName(), sql);
		
		return ad_process_id;
	}

	/* (non-Javadoc)
	 * @see org.compiere.util.ASyncProcess#lockUI(org.compiere.process.ProcessInfo)
	 */
	@Override
	public void lockUI(ProcessInfo pi) {
		// TODO Auto-generated method stub
		
	}

	/* (non-Javadoc)
	 * @see org.compiere.util.ASyncProcess#unlockUI(org.compiere.process.ProcessInfo)
	 */
	@Override
	public void unlockUI(ProcessInfo pi) {
		// TODO Auto-generated method stub
		
	}

	/* (non-Javadoc)
	 * @see org.compiere.util.ASyncProcess#isUILocked()
	 */
	@Override
	public boolean isUILocked() {
		// TODO Auto-generated method stub
		return false;
	}

	/* (non-Javadoc)
	 * @see org.compiere.util.ASyncProcess#executeASync(org.compiere.process.ProcessInfo)
	 */
	@Override
	public void executeASync(ProcessInfo pi) {
		// TODO Auto-generated method stub
		
	}
}
